<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='main'){
	exi($return);
}
/*******op*******/
if($_RQ['op']=='list'){
	//查询进入该页面的客户所有订单
	$pids = pdo_getall('jy_adbaoming_list',array('mid'=>$_SESSION['uid']),array('id'),'id');
	if($pids){
		$pids=array_keys($pids);
	}else{
		$pids=-1;
	}
	$params=array('activity_id'=>$pids,'uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['status']) && intval($_RQ['status'])<10){
		$params['status']=intval($_RQ['status']);
		$return['status']=$_RQ['status'];
	}elseif($_RQ['status']=='10'){
		$return['status']=10;
	}else{
		$return['status']=1;
		$params['status']=1;
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 8;
	$list=pdo_getslice('jy_adbaoming_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
			foreach($list as &$item){
				$user=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar'));
				$info=pdo_get('jy_adbaoming_list',array('id'=>$item['activity_id'],'uniacid'=>$_SESSION['uniacid']),array('title','money'));
				$item['user']=$user;
				$item['info']=$info;
				$item['typestatus']=$item['status']==0?'待支付':'已完成';
				$item['typetitle']=$this->itemtypes()[$info['type']];
				$item['createtime']=date('Y-m-d H:i:s', $item['createtime']);
			}
	}
	$return['list']=$list;
	exi($return);
}
//订单详情
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('订单不存在，请重新选择','error');
	}
	$order=pdo_get('jy_adbaoming_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//用户信息
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['mid']),array('nickname','avatar'));
	//项目信息
	$activity=pdo_get('jy_adbaoming_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['activity_id']));	
	$order['diyfrom']=json_decode($order['diyfrom'],true);
	foreach($order['diyfrom'] as &$v){
		if(($v['type']==4 || $v['type']==5)  && $v['data']){
			$v['data'] = explode(";", $v['data']);
		}
	}
	if($activity['status']==0){
		$activity['typestatus']='待支付';
	}
	if($activity['status']==1){
		$activity['typestatus']='已支付';
	}
	if($activity['status']==2){
		$activity['typestatus']='已发货';
	}
	if($order['status']>=3){
		$order['typestatus']=$order['status']==3?'已取消':'已完成';
	}
	$order['createtime']=date('Y-m-d H:i:s', $order['createtime']);
	$order['sendtime']=date('Y-m-d H:i:s', $order['sendtime']);
	$order['paytime']=date('Y-m-d H:i:s', $order['paytime']);
	$return['order']=$order;
	$return['member']=$member;
	$return['activity']=$activity;
	exi($return);
}